package top.greatxiaozou.prototype;

import java.util.HashMap;

public class ShapeCache {
    private HashMap<String, Shape> map = new HashMap<>();

    public void loadCache() {
        Circle circle = new Circle();
        Square square = new Square();
        Rectangle rectangle = new Rectangle();

        circle.setId("1");
        square.setId("2");
        rectangle.setId("3");

        map.put(circle.getId(), circle);
        map.put(square.getId(), square);
        map.put(rectangle.getId(), rectangle);
    }

    public Shape getShape(String shapeId) throws CloneNotSupportedException {
        Shape clone = (Shape) map.get(shapeId).clone();
        return clone;
    }
}